//
//  TodaySignCell.m
//  sooc-ios_new
//
//  Created by houshijia on 15/12/23.
//  Copyright © 2015年 xuguangChao. All rights reserved.
//

#import "TodaySignCell.h"
#define NUMCOLOR  [UIColor colorWithRed:0.95 green:0.61 blue:0.13 alpha:1]
@implementation TodaySignCell

/*
 ktbh
 ktid		课堂id
 kcmc		课程名称
 lsmc		老师名称
 skdd		上课地点
 ktzt		课堂主题
 qdzt		签到状态（0未签到，1已签到）
 qdri		签到日期（仅历史签到中需要，今日签到该项可以返回空）
 
 */

- (void)awakeFromNib {
    // Initialization code
}

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //
        _kcmcLabel = [[UILabel alloc]init];
        _kcmcLabel.font = NormalFont(42);
        _kcmcLabel.text = @"高等数学";
        _kcmcLabel.numberOfLines = 1;
        _kcmcLabel.textAlignment = NSTextAlignmentLeft;
        _kcmcLabel.textColor = Color333333;
        [self.contentView addSubview:_kcmcLabel];
        [_kcmcLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView.mas_top).offset(ScaleSize(51));
            make.left.equalTo(self.contentView.mas_left).offset(ScaleSize(33));
            make.height.mas_equalTo(@35);
            make.width.equalTo(self.contentView.mas_width).multipliedBy(0.6);
            
        }];
        
        
        
        //
        _numLabel = [[UILabel alloc]init];
        _numLabel.font = NormalFont(42);
        _numLabel.textColor = NUMCOLOR;
        _numLabel.text = @"1";
        _numLabel.textAlignment  =NSTextAlignmentRight;
        [self.contentView addSubview:_numLabel];
        [_numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.and.bottom.equalTo(_kcmcLabel);
            make.right.equalTo(self.contentView.mas_right).offset(-ScaleSize(33));
            make.width.mas_equalTo(@25);

        }];
        //
        _ktbhLabel = [[UILabel alloc]init];
        _ktbhLabel.font = NormalFont(42);
        _ktbhLabel.text = @"编号";
        _ktbhLabel.textColor = Color666666;
        _ktbhLabel.textAlignment  =NSTextAlignmentCenter;
        [self.contentView addSubview:_ktbhLabel];
        [_ktbhLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.and.bottom.equalTo(_kcmcLabel);
            make.right.equalTo(_numLabel.mas_left).offset(ScaleSize(33));
            make.width.equalTo(self.contentView.mas_width).multipliedBy(0.1);
        }];
        
        
        //
        _ktztLabel = [[UILabel alloc]init];
        _ktztLabel.numberOfLines = 1;
        _ktztLabel.textColor = Color666666;
        _ktztLabel.font = NormalFont(42);
        _ktztLabel.text = @"这节课主要讲多元函数";
        _ktztLabel.textAlignment = NSTextAlignmentLeft;
        [self.contentView addSubview:_ktztLabel];
        [_ktztLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_kcmcLabel.mas_bottom).offset(-ScaleSize(21));
            make.left.and.right.and.height.equalTo(_kcmcLabel);
        }];
        
        //
        
        _icon = [[UIImageView alloc]init];
        _icon.image = [UIImage imageNamed:@"我的-课程发布人"];
        [_icon setContentMode:UIViewContentModeScaleAspectFit];
        [self.contentView addSubview:_icon];
        [_icon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_ktztLabel.mas_bottom).offset(ScaleSize(51));
            make.left.equalTo(_ktztLabel);
            make.height.and.width.mas_equalTo(@(ScaleSize(48)));
           
        }];
        //
        _lsmcLabel = [[UILabel alloc]init];
        _lsmcLabel.text = @"李老师";
        _lsmcLabel.textColor = Color999999;
        _lsmcLabel.font = NormalFont(42);
        [self.contentView addSubview:_lsmcLabel];
        [_lsmcLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_icon.mas_top).offset(0);
            make.left.equalTo(_icon.mas_right).offset(5);
            make.height.mas_equalTo(_icon);
            make.width.mas_equalTo(@150);
        }];
        
        //
        _signBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//        _signBtn.hidden = YES;
//        _signBtn.titleLabel.textColor= [UIColor blueColor];
        _signBtn.layer.masksToBounds = YES;
        _signBtn.layer.borderWidth = 0.5;
        _signBtn.layer.cornerRadius = 2;
        _signBtn.layer.borderColor = Color1b97e9.CGColor;
        _signBtn.selected = NO;
        [_signBtn addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside];
        [_signBtn setTitle:@"签到" forState:UIControlStateNormal];
        [_signBtn setTitleColor:Color1b97e9 forState:UIControlStateNormal];
        _signBtn.titleLabel.font = NormalFont(42);
//        [_signBtn setTitle:@"已签到" forState:UIControlStateSelected];
        _signBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:_signBtn];
        [_signBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView.mas_right).offset(-15);
//            make.bottom.equalTo(self.contentView.mas_bottom).offset(-33*SCALE0000);
            make.centerY.equalTo(_lsmcLabel);
            make.height.mas_equalTo(@34);
            make.width.mas_equalTo(@78);
        }];
    
        //
        _hasSignedView = [[UIImageView alloc]init];
        
//        _hasSignedView.backgroundColor =  [UIColor orangeColor];
        _hasSignedView.image = [UIImage imageNamed:@"课堂签到-已签到标识"];
        [_hasSignedView setContentMode:UIViewContentModeScaleToFill];
        [self.contentView  addSubview:_hasSignedView];
        [_hasSignedView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView.mas_right).offset(-15);
            make.bottom.equalTo(self.contentView.mas_bottom).offset(-ScaleSize(28));
            make.height.mas_equalTo(@60);
            make.width.mas_equalTo(@60);
        }];
    }
    
//    UIView *lowView = [[UIView alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(_hasSignedView.frame)+19.5, SIZEWIDTH - 20, 0.5)];
//    lowView.backgroundColor = colordbdbdb;
//    [self.contentView addSubview:lowView];
//    
    return self;
}
//-(void)clickBtn{
//    NSNotificationCenter * defaultCenter = [NSNotificationCenter defaultCenter];
//    if (_signBtn.selected) {
////        [defaultCenter postNotificationName:@"YQStuTodayCellResignClick" object:@"1"];// 按钮为选中状态
////        NSLog(@"1");
//        return;
//    }else{
//        [defaultCenter postNotificationName:@"YQStuTodayCellResignClick" object:_todayModel];
//        NSLog(@"2");
//    }
//
//}
+(TodaySignCell*)cellWithTableview:(UITableView*)tableview{
static NSString *cellId = @"today";
    TodaySignCell *cell = [tableview dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[TodaySignCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
        
    }
    return  cell;
    
}

-(void)setTodayModel:(SignModel *)todayModel{
    
    _todayModel = todayModel;
    _kcmcLabel.text = _todayModel.kcmc;
    _ktztLabel.text = _todayModel.ktzt;
    _lsmcLabel.text = _todayModel.lsmc;
    //课堂编号
    _numLabel.text = _todayModel.ktbh;
    if ([_todayModel.qdzt intValue]==1) {
        _signBtn.hidden = YES;
        _hasSignedView.hidden = NO;
    }else{
        _signBtn.hidden = NO;
        _hasSignedView.hidden = YES;
    }


}

-(void)clickBtn{
    if ([_delegate respondsToSelector:@selector(clickCellSignBtn:)]) {
        [_delegate clickCellSignBtn:_todayModel];
    }
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
